/**
 * 
 */

function sendRating(values) {
	console.log("Service.sendRating : llamada para guardar el rating del lugar.");
 
	$
			.ajax({
				type : "GET",
				data : {
					id : values.id,
					rate : values.rate,
					comment : values.comment
				},
				url : "../rate/add.do",
				dataType : "json",   			    
				success : function(data){
					showToast(PLACE_RATE_SENT, TOAST_OK); 
				},
				error : function(jqXHR, textStatus, errorThrown) {
					if (typeof console == 'object'
							&& typeof console.log == 'function') {
						console.log(jqXHR);
						console.log(textStatus);
						console.log(errorThrown);
					}
					//TODO enviar error pro mail
					showToast( ERROR_SEND_PLACE_RATE, TOAST_ERROR);
				}
			}); 
}


function getPlaces(coor) {
	console.log("Service.getPlaces : llamada para obtener los puntos.");	 
	$
			.ajax({
				type : "GET",
				data : {
					neLat : coor.neLat,
					swLat : coor.swLat,
					neLng : coor.neLng,
					swLng : coor.swLng,
					iList : filterPoints.toString()
				},
				url : "./list.do",
				dataType : "json",  
				crossDomain : true,
			    
				success : checkPlaces,
				error : function(jqXHR, textStatus, errorThrown) {
					if (typeof console == 'object'
							&& typeof console.log == 'function') {
						console.log(jqXHR);
						console.log(textStatus);
						console.log(errorThrown);
					}
				}
			});	 
}


function getPlaceComments() {
	console.log("Service.getPlaceComments : llamada para obtener los commentarios.");	 
	$
			.ajax({
				type : "GET",
				data : {
					id : viewedPlace.id
				},
				url : "../rate/getComments.do",
				dataType : "json",  
				crossDomain : true,			    
				success : showPlaceComments,
				error : function(jqXHR, textStatus, errorThrown) {
					if (typeof console == 'object'
							&& typeof console.log == 'function') {
						console.log(jqXHR);
						console.log(textStatus);
						console.log(errorThrown);
					}
				}
			});
	 
}

function removePlaceComments(remove) {
	console.log("Service.removePlaceComments : llamada para eliminar un lugar.");	 
	$
			.ajax({
				type : "GET",
				data : {
					placeId : remove.placeId,
					reason : remove.reason
				},
				url : "./remove.do",
				dataType : "json",  
				crossDomain : true,			    
				success : function(data){
					showToast(data.message, TOAST_OK); 
					$.mobile.back();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					if (typeof console == 'object'
							&& typeof console.log == 'function') {
						console.log(jqXHR);
						console.log(textStatus);
						console.log(errorThrown);
					}
				}
			});
	 
}